package vashion.azeroth.back.controller.item;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import vashion.azeroth.back.controller.base.BaseController;
import vashion.azeroth.core.result.ApiResult;
import vashion.azeroth.core.item.pojo.ItemBrandDO;
import vashion.azeroth.core.manager.item.BaseItemBrandManager;

/**
 * Created by Loki on 16/1/17.
 *
 */

@Controller
@RequestMapping("/back/brand")
public class BackBrandController<T> extends BaseController {

	private final static Logger log = LoggerFactory.getLogger(BackBrandController.class);
	
	@Autowired
	BaseItemBrandManager BaseItemBrandManager;
	
	@RequestMapping("publishBrand.htm")
    @ResponseBody
    public ApiResult<ItemBrandDO> publishBrand(@ModelAttribute("brandDO") ItemBrandDO brandDO,
                                             @RequestParam(value = "forestIds", required = true) String forestIds,
                                             HttpServletRequest request) {
		ApiResult<Boolean> publishResult = BaseItemBrandManager.publishBrand(brandDO, forestIds, getLoginUserId(request));
		if (publishResult.isSuccess() && publishResult.getData()) {
            return ApiResult.newSuccessResult();
        } else {
            return ApiResult.newErrorResult(publishResult.getErrorCode(), publishResult.getErrorMsg());
        }
	}
}
